<?php

if($info){
    ?>
    <style>
        table.tecspec {
            width: 100%;
            max-width: 100%;
            border-bottom: 1px solid #dddddd;
        }
        table.tecspec>tbody>tr>th,table.tecspec>tbody>tr>td{
            padding: 8px;
            line-height: 1.42857143;
            vertical-align: top;
            border-top: 1px solid #ddd;
        }
        table.tecspec>tbody>tr>th{
            border-right: 1px solid #ddd;
        }
    </style>
    <?php
    echo '<br/>Có '.count($info).' kết quả trả ra:';
    foreach($info as $key => $values){
        echo '<h3>'.$this->lang->line("contacts").' : '. $values->customerID.' </h3>';
        ?>
<table class="tecspec">
            <tbody>
            <tr>
              <th style="width:25%"><?php echo $this->lang->line('name');?></th>
              <td width="75%"><?php echo $values->name;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('address');?></th>
              <td><?php echo $values->address;?></td>
            </tr>
             <tr>
              <th><?php echo $this->lang->line('phone');?></th>
              <td>
                  <?php
                        $phone = json_decode($values->phone);
                        if(count($phone) > 1){
                            echo implode(", ",$phone);
                        } else {
                            echo $phone[0];
                        }
                        
                  ?>
              </td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('birthday');?></th>
              <td><?php echo ($values->birthday != '00-00-0000')?date("d-m-Y",strtotime($values->birthday)):'';?></td>
            </tr>
            <?php
                $social = json_decode($values->social);
            ?>
            <tr>
              <th><?php echo $this->lang->line('skype');?></th>
              <td><?php echo $social->skype;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('yahoo');?></th>
              <td><?php echo $social->yahoo;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('email');?></th>
              <td><?php echo $social->email;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('facebook');?></th>
              <td><?php echo $social->facebook;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('province');?></th>
              <td><?php echo $values->province;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('info_bill');?></th>
              <td><?php echo $values->info_bill;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('totalMoneyKH');?></th>
              <td><?php echo $this->bookinglib->my_number_format($values->totalMoneyBooking, 2, ',', ',').' VNĐ';?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('surplus');?></th>
              <td><?php echo $this->bookinglib->my_number_format($values->surplus, 2, ',', ',').' VNĐ';?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('lastBooking');?></th>
              <td><?php echo ($values->lastBooking != '0000-00-00 00:00:00')?date("d-m-Y H:i:s",strtotime($values->lastBooking)):'';?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('note');?></th>
              <td><?php echo $values->note;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('booker');?></th>
              <td><?php echo $values->username;?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('saler');?></th>
              <td><?php
                    $users =  $this->listcustomers_model->getInfoUserByParams($values->salesID);
                    echo $users->username;
              ?></td>
            </tr>
            <tr>
              <th><?php echo $this->lang->line('lastupdated');?></th>
              <td><?php echo date("d-m-Y H:i:s",$values->lastupdated);?></td>
            </tr>
             <tr>
              <th><?php echo $this->lang->line('agent_code');?></th>
              <td><?php echo $values->agent_code;?></td>
            </tr>
          </tbody>
        </table>
        <?php
        } //end foreach
        die("");
} else {
    $this->load->view('templates/backend/header');
    echo '<h3>'.$this->lang->line('menu_searchCustomers').'</h3>';
    
    echo form_open('/auth/searchCustomers/search',array('id'=>'ajaxform'));
        echo form_label($this->lang->line('name'), 'name');
        echo form_input(array('name' => 'name', 'id' => 'name', 'value' => '', 'placeholder' => 'Vui lòng nhập '.$this->lang->line('name')));
        echo form_error('name');
        
        echo form_label($this->lang->line('phone'), 'phone');
        echo form_input(array('name' => 'phone', 'id' => 'phone', 'value' => '', 'placeholder' => 'Vui lòng nhập '.$this->lang->line('phone')));
        echo form_error('phone');

        echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('search'),'class' => 'btn btn-success')).' <span id="simple-msg-submit"></span>';
    echo form_close();
    
    echo '<div id="content-msg"></div>';

}
?>

<script>
$("#ajaxform").on('submit',function(e)
{
    if($("#name").val().trim == "" && $("#phone").val().trim == ""){
        alert("Vui lòng nhập ít nhất 1 thông tin!");
        return false;
    }
    var postData = $(this).serializeArray();
    var formURL = $(this).attr("action");
    $("#loading-image").show();
    setTimeout(function () {
        $.ajax(
            {
                url : formURL,
                type: "POST",
                data : postData,
                cache: true,
                beforeSend: function(){
                    ///$('button[type="submit"]').attr('disabled','disabled');
                },
                success:function(data) 
                {
                    $("#loading-image").hide();
                    $("#content-msg").html(data);
                },
                error: function() 
                {
                    $("#simple-msg-submit").html('F5 thử lại!!!!!!');
                }
            });
    }, 3000);
    e.preventDefault();	//STOP default action
});
</script>
<?php $this->load->view('templates/backend/footer'); ?>